package com.cln.salesTaxes;

import java.math.BigDecimal;

public class Item implements IItem {
	protected BigDecimal price = new BigDecimal("0");
	protected BigDecimal salesTaxes = new BigDecimal("0");
	protected BigDecimal total = new BigDecimal("0");
	protected String itemName = "";
	protected String catalog = "";
	protected boolean isImported = false;
	protected Taxes taxes = new Taxes();

	public Item() {
		super();
	}

	static public Item createExemptItem(String itemName, String price) {
		return new Item(itemName, price, "books", false);
	}

	static public Item createNormalItem(String itemName, String price) {
		return new Item(itemName, price, "", false);

	}

	static public Item createImportedExemptItem(String itemName, String price) {
		return new Item(itemName, price, "books", true);

	}

	static public Item createImportedNormalItem(String itemName, String price) {
		return new Item(itemName, price, "", true);

	}

	public Item(String itemName, String price, String catelog,
			boolean isImported) {
		this.price = new BigDecimal(price);
		this.itemName = itemName;
		this.catalog = catelog;
		this.isImported = isImported;
		if (isImported()) {
			this.taxes.addTax(new Tax(new BigDecimal("0.05")));
		}

		if (!isExempt()) {
			this.taxes.addTax(new Tax(new BigDecimal("0.1")));
		}

	}

	public BigDecimal getTotal() {
		return getPrice().add(getSalesTaxes());
	}

	public BigDecimal getPrice() {
		return price;
	}

	public BigDecimal getSalesTaxes() {
		return taxes.caculateTaxes(getPrice());
	}

	public String getItemName() {
		return itemName;
	}

	public boolean isExempt() {
		return getCatalog().equals("medical products")
				|| getCatalog().equals("books") || getCatalog().equals("food");
	}

	public boolean isImported() {
		return isImported;
	}

	public String getCatalog() {
		return catalog;
	}

	public void setImported(boolean isImported) {
		this.isImported = isImported;
	}

}
